package com.demo.datastructure.reorder.shellSort;

import com.demo.datastructure.reorder.Example;

/**
 * @author ljr
 * @version 3.0
 * @description: 希尔排序
 * @date 2021/9/17 21:19
 */
public class MyShellSort3 implements Example {

    @Override
    public void sort(Comparable[] a) {
        int n = a.length;
        int h = 1;
        while(h < n/3) h = h*3+1;
        int num = 0;
        while(h >= 1){
            for(int i = h; i < n; i += h){
                for(int j = i; j >= h && less(a[j], a[j-h]); j -= h){
                    exch(a, j, j-h);
                    num++;
                }
            }
            h /= 3;
        }
        System.out.println("总共交换次数为==============="+num);
    }

}
